#include "CoreFactory.hpp"




CoreFactory::CoreFactory(Validator *val,GAmodSettings settings)
{
// Initialization of the enumerate.
s_mapStringCore=t_mapStringCore();
s_mapStringCore["NotDefinedCore"]=NotDefinedCore;
s_mapStringCore["SC"]=SimpleCore;
s_mapStringCore["MPC"]=MultiPopCore;
s_mapStringCore["MPCMT"]=MultiPopCoreMT;
s_mapStringCore["CGA"]=CompactCore;
s_mapStringCore["MGA"]=MGAcore;
s_mapStringCore["ECGA"]=ECGAcore;


selected_validator=val;
selected_settings=settings;
}

GAcore* CoreFactory::getNewGAcore(std::string corename) throw(CoreFactoryException)
{
	//switch to select the right core to return
	switch(s_mapStringCore[corename])
	{
		case SimpleCore:
			{
			try
				{
				return new SimpleCore::SimpleCore(selected_validator,selected_settings);
				}
			catch(EHW_Exception &e)
				{
				printf("[ERROR] %s\n",e.msg.c_str());
				exit(1);
				}
			}break;
			
		case MultiPopCore:
			{
			try
				{
				return new MultiPopCore::MultiPopCore(selected_validator,selected_settings);
				}
			catch(EHW_Exception &e)
				{
				printf("[ERROR] %s\n",e.msg.c_str());
				exit(1);
				}
		  
		    }break;
		case MultiPopCoreMT: 
			{
				try
				{
				return new MultiPopCoreMT::MultiPopCoreMT(selected_validator,selected_settings);
				}
			catch(EHW_Exception &e)
				{
				printf("[ERROR] %s\n",e.msg.c_str());
				exit(1);
				}
		  
		    }break;
		case CompactCore: 
			{
				try
				{
				return new CompactCore::CompactCore(selected_validator,selected_settings);
				}
			catch(EHW_Exception &e)
				{
				printf("[ERROR] %s\n",e.msg.c_str());
				exit(1);
				}
		  
		    }break;
		case MGAcore: 
			{
				try
				{
				return new MGAcore::MGAcore(selected_validator,selected_settings);
				}
			catch(EHW_Exception &e)
				{
				printf("[ERROR] %s\n",e.msg.c_str());
				exit(1);
				}
		  
		    }break;
		case ECGAcore: 
			{
				try
				{
				return new ECGAcore::ECGAcore(selected_validator,selected_settings);
				}
			catch(EHW_Exception &e)
				{
				printf("[ERROR] %s\n",e.msg.c_str());
				exit(1);
				}
		  
		    }break;
		case NotDefinedCore: break;
		default: break;
	}

return NULL;
}

